package handler;

import org.apache.commons.dbutils.ResultSetHandler;
import entity.Admins;

import java.sql.Date;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class CustomBeanListHandler implements ResultSetHandler<List<Admins>> {
    @Override
    public List<Admins> handle(ResultSet rs) throws SQLException {
        List<Admins> adminsList = new ArrayList<>();
        while (rs.next()) {
            Admins admin = new Admins();
            admin.setId(rs.getInt("id"));
            admin.setAdminName(rs.getString("adminName"));
            admin.setAdminPwd(rs.getString("adminPwd"));
            admin.setRealName(rs.getString("realName"));
            admin.setTelephone(rs.getString("telephone"));
            admin.setEmail(rs.getString("email"));
            // 使用 getObject 转换日期类型
            java.sql.Date sqlDate = rs.getDate("birthday");
            if (sqlDate != null) {
                admin.setBirthday(Date.valueOf(sqlDate.toLocalDate()));
            } else {
                admin.setBirthday(null);
            }
            admin.setSex(rs.getString("sex"));
            admin.setPic(rs.getString("pic"));
            admin.setRemark(rs.getString("remark"));
            adminsList.add(admin);
        }
        return adminsList;
    }
}

